package com.example.medicalrecord.AggregationModule.medicineOption.controller;

import com.example.medicalrecord.AggregationModule.medicineOption.pojo.dto.MedicineOptionParam;
import com.example.medicalrecord.AggregationModule.medicineOption.pojo.dto.MedicineOptionQuery;
import com.example.medicalrecord.AggregationModule.medicineOption.pojo.vo.MedicineOptionVO;
import com.example.medicalrecord.AggregationModule.medicineOption.service.MedicineOptionService;
import com.example.medicalrecord.base.response.JsonResult;
import com.example.medicalrecord.base.response.PageData;
import io.swagger.annotations.Api;
import lombok.Getter;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@Api
@RestController
@RequestMapping("/v1/medicineOption")
public class MedicineOptionController {
    @Autowired
    MedicineOptionService medicineOptionService;

    @GetMapping("select")
    public JsonResult selectMedicineOption(MedicineOptionQuery medicineOptionQuery){
        log.debug("查询药品项数据:medicineOptionQuery={}",medicineOptionQuery);
        PageData medicineOptionVOList = medicineOptionService.selectMedicineOption(medicineOptionQuery);
        return JsonResult.ok(medicineOptionVOList);
    }

    @PostMapping("save")
    public JsonResult saveMedicineOption(MedicineOptionParam medicineOptionParam){
        log.debug("保存药品项数据:medicineOptionParam={}",medicineOptionParam);
        medicineOptionService.saveMedicineOption(medicineOptionParam);
        return JsonResult.ok();
    }

    @PostMapping("delete/{id}")
    public JsonResult deleteMedicineOption(@PathVariable Long id){
        log.debug("删除药品数据:id={}",id);
        medicineOptionService.deleteMedicineOption(id);
        return JsonResult.ok();
    }

    @GetMapping("select/{code}")
    public JsonResult selectMedicineOptionByCode(@PathVariable String code){
        log.debug("根据药品类code查询查询药品项数据:code={}",code);
        List<MedicineOptionVO> medicineOptionVOList = medicineOptionService.selectMedicineOptionByCode(code);
        return JsonResult.ok(medicineOptionVOList);
    }

}
